package com.hspedu.encap;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/1/20
 * @time 18:04
 */
public class Encapsulation01 {
    public static void main(String[] args) {
        Person person = new Person();
        person.setAge(200);
        System.out.println(person.getAge());
        person.setName("jackduqe");
        System.out.println(person.getName());
        person.setSal(10000);
        System.out.println(person.getSal());
        Person person1 = new Person(130, 1000, "123456789");
        person1.getInfo();
    }
}

class Person{
    private int age;
    private double sal;
    private String name;

    public Person() {
    }

    public Person(int age, double sal, String name) {
        if (name.length() >= 2 && name.length() < 6){
            this.name = name;
        }else {
            System.out.println("输入不合法");
            this.name = "张三";
        }
        this.age = age;
        this.sal = sal;
    }

    public void setName(String name){
        if (name.length() >= 2 && name.length() < 6){
            this.name = name;
        }else {
            System.out.println("输入不合法");
            this.name = "张三";
        }
    }

    public String getName(){
        return this.name;
    }

    public void setAge(int age){
        if (age > 0 && age < 120){
            this.age = age;
        }else {
            System.out.println("输入不合法");
            this.age = 18;
        }
    }

    public int getAge(){
        return this.age;
    }

    public void setSal(double sal){
        this.sal = sal;
    }

    public double getSal(){
        return this.sal;
    }

    public void getInfo(){
        System.out.println(age+" "+name+" "+sal+" ");
    }


}
